package com.wo.cloud.code.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wo.cloud.code.dto.SysDataSourceDto;
import com.wo.cloud.code.entity.SysDataSource;
import com.wo.cloud.code.mapper.SysDataSourceMapper;
import com.wo.cloud.code.service.ISysDataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/6/17 15:56
 * Description:
 */
@Service
public class SysDataSourceServiceImpl
        extends ServiceImpl<SysDataSourceMapper, SysDataSource> implements ISysDataSourceService {

    @Autowired
    private SysDataSourceMapper sourceMapper;

    // 分页条件查询
    @Override
    public IPage<SysDataSource> getSourcePage(Page page, SysDataSourceDto sysDataSourceDto) {

        IPage<SysDataSource> sysDataSourceIPage = sourceMapper.selectPage(page,
                new LambdaQueryWrapper<SysDataSource>()
                        .eq(StrUtil.isNotBlank(sysDataSourceDto.getDataSourceId()), SysDataSource::getId, sysDataSourceDto.getDataSourceId())
                        .or()
                        .ge(ObjectUtil.isNotNull(sysDataSourceDto.getStartTime()), SysDataSource::getCreateTime, sysDataSourceDto.getStartTime())
                        .lt(ObjectUtil.isNotNull(sysDataSourceDto.getEndTime()), SysDataSource::getCreateTime, sysDataSourceDto.getEndTime())
                        .like(StrUtil.isNotBlank(sysDataSourceDto.getName()), SysDataSource::getName, sysDataSourceDto.getName()));
        return sysDataSourceIPage;
    }
}
